package com.example.retrofit;

import com.alibaba.fastjson.JSON;
import com.example.common.JsonResult;
import com.example.domain.Admin;
import lombok.extern.slf4j.Slf4j;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import java.io.IOException;

/**
 * Created by jianweilin on 16/9/8.
 */
@Slf4j
public class RetrofitBootStrap {
    private static final String LOCAL_HOST = "http://127.0.0.1:8080";

    public static void main(String[] args) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(LOCAL_HOST)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        // retrofit生成UserApi接口实现
        AdminApi service = retrofit.create(AdminApi.class);

        Call<JsonResult<Admin>> postMsg = service.get("zhangsan", "123456");
        try {
            // 创建同步远程请求
            System.out.println(JSON.toJSONString(postMsg.execute().body()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
